from mg_app_framework import (IdiServerConfigBasic, InitFuncBasic, TaskKey, app_start,
                              set_config_func, set_init_task, set_store, set_context)
from mg_app_framework.components import TASKS
from common.basic_redis import redis_async_connect
from common.http_client import set_aiohttp_session
from prod_ctrl_service.config import RedisConfigBasic, ConfigStore
from prod_ctrl_service.rabbitmq import get_subscribe_message_cache, RabbitMQConfig
from prod_ctrl_service.tool.tool import get_process_info


async def config_process():
    """

    :return:
    """
    pass


class InitFuncConfig(InitFuncBasic):
    """111"""

    async def init_func(self):
        """

        :return:
        """
        await get_subscribe_message_cache()
        # 初始化工序编码与工序号的映射
        await get_process_info()


def main(debug_flag=True):
    """

    :param debug_flag:
    :return:
    """
    TASKS[TaskKey.redis_async] = redis_async_connect

    import uvloop

    uvloop.install()

    set_aiohttp_session()
    set_store(ConfigStore())
    set_config_func(config_process)
    set_context("upperpc_code_list", [])
    set_context("call_id_list", [])
    set_context("device_code_list", [])
    set_context("device_code_name_map", {})
    set_context("process_code_sequence_map", {})
    set_init_task(
        [
            {TaskKey.idi_server: IdiServerConfigBasic()},
            {TaskKey.rabbitmq_async: RabbitMQConfig()},
            {TaskKey.redis_async: RedisConfigBasic()},
            {TaskKey.init_func: InitFuncConfig()},
        ]
    )
    app_start(debug_flag)
